let studentsModel = require("../models/studentsModel")

// 学生信息添加
// exports.addstudent = (req,res)=>{
//     let {name,student_id,class_id,enrol_date,graduate_date,ed_sys,ed_bkg,call_ed_bkg,state,phone,egy_person,egy_phone,
//         native_place,address,email} = req.body
//     let p = studentsModel.StudentsModel.createstudent([name,student_id,class_id,enrol_date,graduate_date,ed_sys,ed_bkg,
//         call_ed_bkg,state,phone,egy_person,egy_phone,native_place,address,email])
//     p.then((results)=>{
//           
//         res.json({code:0,msg:"学生信息添加成功！",results})
//     }).catch((error)=>{
//         console.log(error)
//         res.json({code:-1,msg:"学生信息添加失败！",error})
//     })
// }
// class类应用
class StudentsController {
    // 学生信息添加
    static addstudent(req, res) {
        let { name, gender, class_id, enrol_date, graduate_date, ed_sys, ed_bkg, call_ed_bkg, state, phone, egy_person, egy_phone,
            native_place, address, email } = req.body

        console.log("用户提交的参数：", name, gender, class_id, enrol_date, graduate_date, ed_sys,
            ed_bkg, call_ed_bkg, state, phone, egy_person, egy_phone, native_place, address, email)
        let p = studentsModel.createstudent({
            name, gender, class_id, enrol_date, graduate_date, ed_sys,
            ed_bkg, call_ed_bkg, state, phone, egy_person, egy_phone, native_place, address, email
        })
        p.then((results) => {

            res.json({ code: 0, msg: "学生信息添加成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "学生信息添加失败！", error })
        })
    }
    // 学生信息删除--软删除
    static delete_student_f_c(req, res) {
        let { id } = req.query
        console.log("禁用的用户ID：", id)
        let p = studentsModel.delete_student_f(id)
        p.then((results) => {

            res.json({ code: 0, msg: "学生信息禁用成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "学生信息禁用失败！", error })
        })
    }
    // 学生信息删除--软删除
    static start(req, res) {
        let { id } = req.query
        let p = studentsModel.start_state(id)
        p.then((results) => {

            res.json({ code: 0, msg: "学生信息启用成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "学生信息启用失败！", error })
        })
    }
    // 学生信息删除--真删除
    static delete_student_t_c(req, res) {
        let { id } = req.query
        let p = studentsModel.delete_student_t(id)
        p.then((results) => {

            res.json({ code: 0, msg: "学生信息删除成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "学生信息删除失败！", error })
        })
    }
    // 点击查看学生详细信息 && 学生信息修改--获取数据
    static student_view_c(req, res) {
        let { id } = req.query
        let p = studentsModel.student_view(id)

        p.then((results) => {

            res.json({ code: 0, msg: "查看学生详细信息成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "查看学生详细信息失败！", error })
        })
    }
    // 学生信息修改--保存数据
    static student_set_c(req, res) {
        let { name, gender, class_id, enrol_date, graduate_date, ed_sys, ed_bkg, call_ed_bkg, state, phone,
            egy_person, egy_phone, native_place, address, email, id } = req.body
        console.log("用户传过来的参数：：", req.body)
        let p = studentsModel.student_set([name, gender, class_id, enrol_date, graduate_date, ed_sys,
            ed_bkg, call_ed_bkg, state, phone, egy_person, egy_phone, native_place, address, email, id])

        p.then((results) => {

            res.json({ code: 0, msg: "学生信息修改成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "学生信息修改失败！", error })
        })
    }
    // 学生信息列表搜索+分页功能
    static student_list_c(req, res) {
        let { name, student_id, phone, class_id, program_id, ed_sys, state, page, page_size } = req.query
        let p = studentsModel.student_list(name, student_id, phone, class_id, program_id, ed_sys, state, page, page_size)

        p.then((results) => {

            res.json({ code: 0, msg: "学生信息列表搜索请求成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "学生信息列表搜索请求失败！", error })
        })
    }
    // 总学生数
    static all_student_c(req, res) {
        let p = studentsModel.all_student()
        p.then((results) => {

            res.json({ code: 0, msg: "总学生数请求成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "总学生数请求失败！", error })
        })
    }
    // 所有班级名字
    static all_class(req, res) {
        let p = studentsModel.all_class()
        p.then((results) => {

            res.json({ code: 0, msg: "所有班级名字请求成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "所有班级名字请求失败！", error })
        })
    }
    // 所有专业名字
    static all_program(req, res) {
        let p = studentsModel.all_program()
        p.then((results) => {

            res.json({ code: 0, msg: "所有专业名字请求成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "所有专业名字请求失败！", error })
        })
    }

    // 所有专业对应的班级
    static pro_class(req, res) {
        const { program_id } = req.query
        let p = studentsModel.pro_class(Number(program_id))
        p.then((results) => {

            res.json({ code: 0, msg: "专业对应的班级请求成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "专业对应的班级请求失败！", error })
        })
    }

    // 所有考试
    static all_exams(req, res) {
        const { class_id, program_id } = req.query
        let p = studentsModel.all_exams(Number(class_id), Number(program_id))
        p.then((results) => {
            res.json({ code: 0, msg: "所有考试请求成功！", results })
        }).catch((error) => {
            console.log(error)
            res.status(500).json({ code: -1, msg: "所有考试请求失败！", error })
        })
    }
}
module.exports = StudentsController